<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<br/>
<button type="button" onclick="add()" class="btn btn-info">添加店铺</button>
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">
    <form class="form-inline" action="{:url('index/shop/index')}" method="get">
        <input type="text" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >
        <input type="submit" class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res()" value="全部显示" class="btn btn-default"/>
    </form>
</div>
<table class="table table-bordered" style="width: 100%;margin: 0 auto">
    <tr>
        <th>编号</th>
        <th>店铺联系人</th>
        <th>联系电话</th>
        <th>地址</th>
        <th>操作</th>
    </tr>
    {foreach $result as $val}
    <tr id="del{$val.id}" style="text-align: center">
        <td>{$val.id}</td>
        <td style="width: 200px">{$val.linkman}</td>
        <td>{$val.telephone}</td>
        <td>{$val.address}</td>
        <td>
            <button onclick="tea({$val.id})" type="button" class="btn btn-primary btn-xs">查看茶</button>
            <button onclick="del({$val.id})" type="button" class="btn btn-danger btn-xs">删除</button>
            <button onclick="edit({$val.id})" type="button" class="btn btn-primary btn-xs" >修改</button>
            <button onclick="order({$val.id})" type="button" class="btn btn-info btn-xs" >查看订单</button>
            <button onclick="damagenum({$val.id})" type="button" class="btn btn-warning btn-xs" >损坏个数</button>
            <button onclick="inventory({$val.id})" type="button" class="btn btn-success btn-xs" >查看库存</button>
            <button onclick="purchase({$val.id})" type="button" class="btn btn-default btn-xs">线下购买记录</button>
            <button onclick="onlinepurchase({$val.id})" type="button" class="btn btn-default btn-xs">线上购买记录</button>
            <button onclick="settlement({$val.id})" type="button" class="btn btn-link btn-xs" >线下结算</button>
            <button onclick="online({$val.id})" type="button" class="btn btn-link btn-xs" >线上结算</button>
        </td>
    </tr>
    {/foreach}
</table>
<div style="margin-left: 30px">{$result->render()}</div>
</body>
<script>
    //查看订单
    function order(sid) {
        window.location.href = "{:url('index/shop/order')}?sid="+sid;
    }
    //显示全部
    function res() {
        window.location.href = "{:url('index/shop/index')}";
    }
    //修改
    function edit(id) {
        window.location.href = "{:url('index/shop/edit')}?id="+id;
    }
    //添加店铺
    function add() {
        window.location.href = "{:url('index/shop/add')}";
    }
    //查看损坏个数
    function damagenum(id) {
        window.location.href = "{:url('index/shop/damagenum')}?id="+id;
    }
    //查看库存
    function inventory(id) {
        window.location.href = "{:url('index/shop/inventory')}?id="+id;
    }
    //删除
    function del(id) {
        layer.confirm('你确定要删除吗',{bnt:['确定','取消']},
            function () {
                $.ajax({
                    url:"{:url('index/shop/delete')}",
                    data:"id="+id,
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        if(data.success){
                            layer.alert('删除成功',{bnt:['确定','取消']},
                                function () {
                                    window.location.reload();
                                },function () {
                                    window.location.reload();
                                }
                            );
                        }
                        if(data.error){
                            layer.alert(data.error);
                        }
                    }
                });
            }
        );
    }
    //结算
    function settlement(sid) {
        window.location.href = "{:url('index/orders/index')}?sid="+sid;
    }
    //线上结算
    function online(sid) {
        window.location.href = "{:url('index/onlineorder/index')}?sid="+sid;
    }
    //购买记录
    function purchase(sid) {
        window.location.href = "{:url('index/orders/purchase')}?sid="+sid;
    }
    //线上购买记录
    function onlinepurchase(sid) {
        window.location.href = "{:url('index/onlineorder/onlinepurchase')}?sid="+sid;
    }
    //查看茶
    function tea(id) {
        window.location.href = "{:url('index/tea/index')}?id="+id;
    }
</script>
</html>